nums = [2, 2, 1, 1, 1, 2, 2]

var majorityElement = function (nums) {
    nums.sort((a, b) => a - b)
    let len = nums.length
    if (len < 2) return nums[0]
    let count = 1
    for (let i = 1; i < len; i++) {
        if (nums[i] === nums[i - 1]) {
            count++
            if (count > len / 2) {
                return nums[i]
            }
        } else {
            count = 1
        }
    }
};
console.log(majorityElement(nums));
